import React from 'react'
import Button, { ButtonProps } from 'antd/lib/button'
import { uaaApp } from '@/lib'

function UdAuthButton(props: IUdAuthButtonProps) {
  const { auth, ...rest } = props
  let node
  if (auth !== undefined) {
    if (uaaApp.canUse(auth)) {
      node = <Button {...rest}>{props.children}</Button>
    } else {
      node = null
    }
  } else {
    node = <Button {...rest}>{props.children}</Button>
  }
  return node
}

export default React.memo(UdAuthButton)

interface IUdAuthButtonProps extends ButtonProps {
  /** 权限customId */
  auth?: string
}